<%--
  @desc: 统计列表首页
  @author: chenw
  @create: 2014-4-29 下午 15:32
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<div class="pageHeader">
    <form rel="pageForm" onsubmit="return beforeSub(this);" action="<c:url value='/statistic/index'/>"
          method="get">
        <div class="searchBar">
            <ul>
                <li style="float: left;line-height: 25px;">
                    <label style="width:60px;">统计时间：</label>
                    <input id="start" name="start" type="text" class="date" dateFmt="yyyy-MM-dd 00:00:00"
                           value="<fmt:formatDate value="${query.start}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                           placeholder="起始时间"
                           style="width:100px;font-family:'微软雅黑 sans-serif serif';"/>
                    -
                    <input id="end" name="end" type="text" class="date" dateFmt="yyyy-MM-dd 23:59:59"
                           value="<fmt:formatDate value="${query.end}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                           placeholder="结束时间"
                           style="width:100px;font-family:'微软雅黑 sans-serif serif';"/>
                </li>
                <li style="float: left;line-height: 25px;">
                    <label style="width:60px;">平台选择：</label> 
                    <select name="handler">
	                    <option value="" selected="selected">全部</option>
	                    <option value="2"
	                    	<c:if test="${query.handler=='2'}">selected="selected"</c:if>>android
	                    </option>
	                    <option value="1"
	                    	<c:if test="${query.handler=='1'}">selected="selected"</c:if>>ios
	                    </option>
                	</select>
                </li>
                <li style="float: left;line-height: 25px;">
                    <div class="buttonActive" style="margin-left: 5px;">
                        <div class="buttonContent">
                            <button type="submit">查找</button>
                        </div>
                    </div>
                </li>
                <li style="float: left;line-height: 25px;">
                    <div class="buttonActive" style="margin-left: 5px;">
                        <div class="buttonContent">
                            <button type="button" onclick="exportExcel()">导出</button>
                        </div>
                    </div>
                </li> 
            </ul>
        </div>
    </form>
</div>

<div class="pageContent" style="padding-top: 1px;" >
    <table class="table" width="100%" >
    	<thead><tr><td height="25" align="center" colspan="4">APP软件统计明细</td></tr></thead>
    	<tbody>
    		<tr><td align="center">新增下载数</td><td align="center">${appInfoAll.DOWN_NUM==null?'0':appInfoAll.DOWN_NUM }</td>
    		    <td align="center">累计下载数</td><td align="center">${appInfoAll.DOWN_NUM_ALL==null?'0':appInfoAll.DOWN_NUM_ALL}</td></tr>
    		<tr><td align="center">新增使用数</td><td align="center">${appInfoAll.USE_NUM==null?'0':appInfoAll.USE_NUM }</td>
    		    <td align="center">累计使用数</td><td align="center">${appInfoAll.USE_NUM_ALL==null?'0':appInfoAll.USE_NUM_ALL}</td></tr>
    		<tr><td align="center">新增注册数</td><td align="center">${appInfoAll.RIG_NUM==null?'0':appInfoAll.RIG_NUM }</td>
    		    <td align="center">累计注册数</td><td align="center">${appInfoAll.RIG_NUM_ALL==null?'0':appInfoAll.RIG_NUM_ALL}</td></tr>
    		<tr><td align="center">新增用户反馈数</td><td align="center">${appInfoAll.REPLY_NUM==null?'0':appInfoAll.REPLY_NUM }</td>
    		    <td align="center">累计用户反馈数</td><td align="center">${appInfoAll.REPLY_NUM_ALL==null?'0':appInfoAll.REPLY_NUM_ALL }</td></tr>
    	</tbody>
    </table> 
    <table class="table" class="table" width="100%" layoutH="200">
    	<thead><tr><td height="25" colspan="5" align="center">应用统计明细</td></tr></thead>
        <tbody>
        	<c:forEach var="statistic" items="${statistics}" >
	            <tr>
	            	<%-- <td align="center" style="font-size: 14px;font-weight: bold;">${statistic.key.name }</td> --%>
	            	<c:choose>
        				<c:when test="${statistic.key.id == -1}">
        					<td>&nbsp;</td><td>&nbsp;</td>
        					<td align="center">新增信息数</td>
		            		<td align="center">累计信息数</td>
		            		<td align="center">新增浏览数</td>
		            		<td align="center">累计浏览数</td>
	            		</c:when>
        				<c:when test="${statistic.key.id == -3}">
        					<td>&nbsp;</td><td>&nbsp;</td>
		            		<td align="center">新增成功数</td>
		            		<td align="center">累计成功数</td>
        					<td align="center">新增使用数</td>
		            		<td align="center">累计使用数</td>
	            		</c:when>
        				<c:when test="${statistic.key.id == -5}">
        					<td>&nbsp;</td><td>&nbsp;</td>
		            		<td align="center">新增使用数</td>
		            		<td align="center">累计使用数</td>
        					<td align="center">新增浏览数</td>
		            		<td align="center">累计浏览数</td>
	            		</c:when>
	            		<c:otherwise>
	            			<td>&nbsp;</td><td>&nbsp;</td>
	            			<td align="center">新增下载数</td>
		            		<td align="center">累计下载数</td>
		            		<td align="center">新增使用数</td>
		            		<td align="center">累计使用数</td>
	            		</c:otherwise>
	            	</c:choose>
	            </tr>
	        	<c:forEach var="subStatistic" items="${statistic.value}" varStatus="account">
	            	<tr>
	            		<c:if test="${account.count == 1 }">
	            			<td align="center" rowspan="<c:out value='${fn:length(statistic.value)}'/>">${statistic.key.name }</td>
	            		</c:if>
	            		<td align="center">${subStatistic.name }</td>
	            		<c:choose>
	            			<c:when test="${subStatistic.pid != -7}">
	            				<td align="center">${subStatistic.useNum==null?'0':subStatistic.useNum }</td>
	            				<td align="center">${subStatistic.useNumAll==null?'0':subStatistic.useNumAll }</td>
	            			</c:when>
	            			<c:otherwise>
	            				<td align="center">${subStatistic.downNum==null?'0':subStatistic.downNum }</td>
	            				<td align="center">${subStatistic.downNumAll==null?'0':subStatistic.downNumAll }</td>
	            			</c:otherwise>
	            		</c:choose>
	            		<td align="center">${subStatistic.viewNum==null?'0':subStatistic.viewNum  }</td>
	            		<td align="center">${subStatistic.viewNumAll==null?'0':subStatistic.viewNumAll  }</td>
	            	</tr>
	            </c:forEach>
	        </c:forEach>
        </tbody>
    </table>
</div>
<script type="text/javascript">
	function beforeSub(obj){
		var end = $("#end").val().replace("-","/");//替换字符，变成标准格式  
		var start = $("#start").val().replace("-","/");//替换字符，变成标准格式  
		var d1 = new Date();
		if(end != null && end != '' ){
			var d2 = new Date(Date.parse(end));
			if(d1<d2){
				alertMsg.info("今日统计尚未生成，只能查询昨日之前的统计数据");
				return false;
			}
		}
		if(start != null && start != '' ){
			var d3 = new Date(Date.parse(start));
			if(d1<d3){
				alertMsg.info("今日统计尚未生成，只能查询昨日之前的统计数据");
				return false;
			}
		}
		if(start != null && start != '' && end != null && end != '' ){
			var d2 = new Date(Date.parse(end));
			var d3 = new Date(Date.parse(start));
			if(d2<d3){
				alertMsg.info("开始时间不能晚于结束时间！");
				return false;
			}
		}
		return navTabSearch(obj);
	}
	function exportExcel(){
		var handler = "${query.handler}";
		location.href="<c:url value='/statistic/exportExcel.xls?handler="+handler+"&start="+$("#start").val()+"&end="+$("#end").val()+"'/>";
	}
</script>

